package com.sdhs.paas.sdk.core.jdbc.pool;

import org.apache.tomcat.jdbc.pool.DataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;



/**
 * 数据库功能自动配置
 *
 * @author wjj
 *
 */
@Configuration // 配置注解
public class PaasDSAutoConfiguration {

	
	
    @Bean
    @RefreshScope
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
//        return (DataSource) DataSourceBuilder.create().build();
    	return DataSourceBuilder.create().type(DataSource.class).build();
    }
	
	@Bean
	@RefreshScope
	@ConditionalOnMissingBean(PaasDS.class) 
	public PaasDS createPaasDs() {
		PaasDS PaasDs = new PaasDS();
		return PaasDs;
	}

}
